package com.tanhua.app.controller;

import com.tanhua.app.service.SmallVideosService;
import com.tanhua.model.mongo.Video;
import com.tanhua.model.vo.PageResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.io.IOException;
import java.nio.file.Path;
import java.util.List;

@RestController
@RequestMapping("/smallVideos")
public class SmallVideoController {

    @Autowired
    private SmallVideosService smallVideosService;

    /**
     * 发布视频
     *  接口路径：POST
     *  请求参数：
     *      videoThumbnail：封面图
     *      videoFile：视频文件
     */
    @PostMapping
    private ResponseEntity saveVideos(MultipartFile videoThumbnail, MultipartFile videoFile) throws IOException {
        //1.通过Service执行业务逻辑
        smallVideosService.saveVideos(videoThumbnail,videoFile);

        //2.返回结果
        return ResponseEntity.ok(null);
    }


    /**
     * 查询小视频列表（分页查询，先查推荐视频）
     * @return
     */
    @GetMapping
    public ResponseEntity queryVideoList(
            @RequestParam(defaultValue = "1")Integer page,
            @RequestParam(defaultValue = "10")Integer pagesize
    ){
        //1.通过Service执行业务逻辑
        PageResult pageResult = smallVideosService.queryVideoList(page,pagesize);

        //2.返回结果
        return ResponseEntity.ok(pageResult);
    }
}
